package com.yanfan.usersmart.user.firemain.data;


import lombok.Data;

import java.text.SimpleDateFormat;


/**
 * 模拟
 * 模拟量
 *
 * @author TDS
 * @date 2022/08/23
 */
@Data
public class Analog  {

	/**
	 * 信息体
	 */
	private Integer status;
	private AnalogQuantity analogQuantity;

	private String device_id;

	public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public Analog(String message,String deviceId) {
		this.device_id = deviceId;

		analogQuantity = new AnalogQuantity();
		analogQuantity.setSystemType(Integer.parseInt(message.substring(0, 2), 16));
		analogQuantity.setFireMainCode(Integer.parseInt(message.substring(2, 4), 16));
		analogQuantity.setPartType(Integer.parseInt(message.substring(4, 6), 16));
		analogQuantity.setAddressNo(String.valueOf(Integer.parseInt(message.substring(8, 10) +
				message.substring(6, 8), 16)));

		analogQuantity.setLoopNo(String.valueOf(Integer.parseInt(message.substring(12, 14) +
				message.substring(10, 12), 16)));
		analogQuantity.setAnalogType(Integer.parseInt(message.substring(14, 16), 16));
		analogQuantity.setAnalogValue(Integer.parseInt(message.substring(16, 20), 16));

		String time = message.substring(20);
		String ms = String.valueOf(Integer.parseInt(time.substring(0, 2), 16));
		String min = String.valueOf(Integer.parseInt(time.substring(2, 4), 16));
		String hour = String.valueOf(Integer.parseInt(time.substring(4, 6), 16));
		String day = String.valueOf(Integer.parseInt(time.substring(6, 8), 16));
		String month = String.valueOf(Integer.parseInt(time.substring(8, 10), 16));
		String year = String.valueOf(Integer.parseInt(time.substring(10), 16));


		analogQuantity.setUpTime("20" + year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + ms);

	}

}
